<DOCTYPE html>
    <html>

    <head>

        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1.0">
        <meta name="renderer" content="webkit">
        <base href="${rc.contextPath}/">
        <title>优惠信息</title>

    <#include "/commons/stylesheets.ftl">
		<link href="/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
        <link href="/css/plugins/chosen/chosen.css" rel="stylesheet">
        <link href="/css/plugins/iCheck/custom.css" rel="stylesheet">
        <link href="/jquery-select2/select2.min.css" rel="stylesheet">
        <link href="/layer/skin/layer.css" rel="stylesheet">
        
        <#include "/commons/stylesheets.ftl">

    <link href="/css/plugins/iCheck/custom.css" rel="stylesheet">
    <link href="/css/plugins/datapicker/datepicker3.css" rel="stylesheet">
    <link href="/layer/skin/layer.css" rel="stylesheet">
        
    </head>

    <body>
    <div class="container-fluid">

        <div class="wrapper wrapper-content animated fadeInRight">
            <div class="row">
                <div class="col-sm-12">
                    <div class="ibox float-e-margins">
                        <div class="ibox-content">
                            <form class="form-horizontal m-t" id="signform">
                            <#include "form.ftl">

                                <div class="form-group">
                                    <div class="col-xs-9 col-xs-offset-3">
                                        <button class="btn btn-primary" type="submit">保存
                                        </button>
                                        <button class="btn btn-white" type="button" 
                                                onclick="window.parent.layer.closeAll()">取消
                                        </button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>
            </div>
        </div>
    </div>

    <#include "/commons/scripts.ftl">
 	<script src="/js/plugins/validate/jquery.validate.min.js"></script>
    <script src="/js/plugins/validate/messages_zh.min.js"></script>

    <script src="/layer/layer.js"></script>
    <script src="/js/app.js"></script>
    
    <!-- WdatePickerr -->
    <script src="/js/plugins/My97DatePicker/WdatePicker.js"></script>

    <!-- Chosen -->
    <script src="/js/plugins/chosen/chosen.jquery.js"></script>
    <script>
    
   	 $.validator.setDefaults({
            highlight:function(a){
                $(a).closest(".form-group").removeClass("has-success").addClass("has-error")
            },
            success:function(a){a.closest(".form-group").removeClass("has-error").addClass("has-success")},
            errorElement:"span",
            errorPlacement:function(a,b){
                if(b.is(":radio")||b.is(":checkbox")){
                    a.appendTo(b.parent().parent().parent())
                }else{
                    a.appendTo(b.parent())
                }
            },
            errorClass:"help-block m-b-none",
            validClass:"help-block m-b-none"
        });

        
        function saveForm() {
            var form = $("#signform");
            
            $.getJSON("coupon/addDo", serializeForm(form), function (resp) {
                if (resp.resultCode == "success") {
                    layer.alert('保存成功', function () {
                        console.log("###");
                        window.parent.search();
                        console.log(window.parent.refreshTable)
                        window.parent.layer.closeAll();

                    });
                } else {
                    var msg = resp.msg;
                    layer.msg(msg);
                }
            });
        }

        function getServiceTypes() {
            var servicetype = $("#serviceType");
            var sibling = $(servicetype).next();
            var obj = $(sibling).find("li.search-choice").find("a");
            var values = "";
            for (var i = 0; i < obj.length; i++) {
                var index = $(obj[i]).attr("data-option-array-index");
                var option = $("#serviceType").get(0).options[index].value;
                values = values + option + ",";
            }
            if (values == "") {
                values = 0;
            }
            $("#services").val(values);
        }
        
         $().ready(function(){
         
         	
            var a="<i class='fa fa-times-circle'></i> ";
            $("#signform").validate({
            	debug:true,
                rules:{
                    couponName:"required",
                    couponNum:"required",
                    validBegin:"required",
                    validEnd:{required:true,compareStartDate:"#start"},
                    number:{digits:true,positiveInteger:true}
                    
                },
                messages:{
                	validEnd:{compareStartDate:"结束日期要大于开始日期"},
                    number:{digits:"必须输入整数",positiveInteger:"必须输入正整数"}
                },
                success : function(label) {
                    label.closest('.form-group').removeClass('has-error');
                    label.remove();
                },
                errorPlacement : function(error, element) {
                    element.parent('div').append(error);
                },
                
                submitHandler : function(form) {
                	 getServiceTypes();
                     saveForm();
                }
                
            });

            jQuery.validator.addMethod("positiveInteger", function(value, element) {
                var aint=parseInt(value);
                return aint>0&& (aint+"")==value;
            }, "请输入正整数");

            //结束时间要大于开始时间
            jQuery.validator.methods.compareStartDate = function(value, element, param) {
                var startDate = jQuery(param).val();

                var startTime = new Date(startDate.replace(/-/g,"/"));
                var endTime = new Date(value.replace(/-/g,"/"));
                return startTime < endTime;
            };
        });
    </script>

    <script>
        $().ready(function () {

            var d = $(".image-crop > img");
            $(d).cropper({
                             aspectRatio: 1.618,
                             preview: ".img-preview",
                             done: function (k) {
                             }
                         });
            var e = $("#inputImage");
            if (window.FileReader) {
                e.change(function () {
                    var k = new FileReader(), m = this.files, l;
                    if (!m.length) {
                        return
                    }
                    l = m[0];
                    if (/^image\/\w+$/.test(l.type)) {
                        k.readAsDataURL(l);
                        k.onload = function () {
                            e.val("");
                            d.cropper("reset", true).cropper("replace", this.result)
                        }
                    } else {
                        showMessage("请选择图片文件")
                    }
                })
            } else {
                e.addClass("hide")
            }
            $("#download").click(function () {
                window.open(d.cropper("getDataURL"))
            });
            $("#zoomIn").click(function () {
                d.cropper("zoom", 0.1)
            });
            $("#zoomOut").click(function () {
                d.cropper("zoom", -0.1)
            });
            $("#rotateLeft").click(function () {
                d.cropper("rotate", 45)
            });
            $("#rotateRight").click(function () {
                d.cropper("rotate", -45)
            });
            $("#setDrag").click(function () {
                d.cropper("setDragMode", "crop")
            });
            $("#data_1 .input-group.date").datepicker({
                                                          todayBtn: "linked",
                                                          keyboardNavigation: false,
                                                          forceParse: false,
                                                          calendarWeeks: true,
                                                          autoclose: true
                                                      });
            $("#data_2 .input-group.date").datepicker({
                                                          startView: 1,
                                                          todayBtn: "linked",
                                                          keyboardNavigation: false,
                                                          forceParse: false,
                                                          autoclose: true,
                                                          format: "yyyy-mm-dd"
                                                      });
            $("#data_3 .input-group.date").datepicker({
                                                          startView: 2,
                                                          todayBtn: "linked",
                                                          keyboardNavigation: false,
                                                          forceParse: false,
                                                          autoclose: true
                                                      });
            $("#data_4 .input-group.date").datepicker({
                                                          minViewMode: 1,
                                                          keyboardNavigation: false,
                                                          forceParse: false,
                                                          autoclose: true,
                                                          todayHighlight: true
                                                      });
            $("#data_5 .input-daterange").datepicker(
                    {keyboardNavigation: false, forceParse: false, autoclose: true});
            var c = document.querySelector(".js-switch");
            var b = new Switchery(c, {color: "#1AB394"});
            var j = document.querySelector(".js-switch_2");
            var g = new Switchery(j, {color: "#ED5565"});
            var i = document.querySelector(".js-switch_3");
            var f = new Switchery(i, {color: "#1AB394"});
            $(".i-checks").iCheck({
                                      checkboxClass: "icheckbox_square-green",
                                      radioClass: "iradio_square-green"
                                  });
            $(".colorpicker-demo1").colorpicker();
            $(".colorpicker-demo2").colorpicker();
            $(".colorpicker-demo3").colorpicker();
            function h() {
                var k = $("body")[0].style;
                $("#demo_apidemo").colorpicker({color: k.backgroundColor})
                        .on("changeColor", function (l) {
                            k.backgroundColor = l.color.toHex()
                        });
                $("#demo_forceformat").colorpicker({format: "rgba", horizontal: true});
                $(".demo-auto").colorpicker();
                $(".disable-button").click(function (l) {
                    l.preventDefault();
                    $("#demo_endis").colorpicker("disable")
                });
                $(".enable-button").click(function (l) {
                    l.preventDefault();
                    $("#demo_endis").colorpicker("enable")
                })
            }

            h();
            $(".demo-destroy").click(function (k) {
                k.preventDefault();
                $(".demo").colorpicker("destroy");
                $(".disable-button, .enable-button").off("click")
            });
            $(".demo-create").click(function (k) {
                k.preventDefault();
                h()
            });
            var a = $(".back-change")[0].style;
            $("#demo_apidemo").colorpicker({color: a.backgroundColor})
                    .on("changeColor", function (k) {
                        a.backgroundColor = k.color.toHex()
                    });
            $(".clockpicker").clockpicker();
            $('#file-pretty input[type="file"]').prettyFile()
        });
        var config = {
            ".chosen-select": {},
            ".chosen-select-deselect": {allow_single_deselect: true},
            ".chosen-select-no-single": {disable_search_threshold: 10},
            ".chosen-select-no-results": {no_results_text: "Oops, nothing found!"},
            ".chosen-select-width": {width: "95%"}
        };
        for (var selector in config) {
            $(selector).chosen(config[selector])
        }
        $("#ionrange_1").ionRangeSlider({
                                            min: 0,
                                            max: 5000,
                                            type: "double",
                                            prefix: "&yen;",
                                            maxPostfix: "+",
                                            prettify: false,
                                            hasGrid: true
                                        });
        $("#ionrange_2").ionRangeSlider({
                                            min: 0,
                                            max: 10,
                                            type: "single",
                                            step: 0.1,
                                            postfix: " 克",
                                            prettify: false,
                                            hasGrid: true
                                        });
        $("#ionrange_3").ionRangeSlider({
                                            min: -50,
                                            max: 50,
                                            from: 0,
                                            postfix: "°",
                                            prettify: false,
                                            hasGrid: true
                                        });
        $("#ionrange_4").ionRangeSlider({
                                            values: ["一月", "二月", "三月", "四月", "五月", "六月",
                                                     "七月", "八月", "九月", "十月", "十一月",
                                                     "十二月"],
                                            type: "single",
                                            hasGrid: true
                                        });
        $("#ionrange_5").ionRangeSlider({
                                            min: 10000,
                                            max: 100000,
                                            step: 100,
                                            postfix: " km",
                                            from: 55000,
                                            hideMinMax: true,
                                            hideFromTo: false
                                        });
        $(".dial").knob();
        $("#basic_slider").noUiSlider({
                                          start: 40,
                                          behaviour: "tap",
                                          connect: "upper",
                                          range: {"min": 20, "max": 80}
                                      });
        $("#range_slider").noUiSlider({
                                          start: [40, 60],
                                          behaviour: "drag",
                                          connect: true,
                                          range: {"min": 20, "max": 80}
                                      });
        $("#drag-fixed").noUiSlider({
                                        start: [40, 60],
                                        behaviour: "drag-fixed",
                                        connect: true,
                                        range: {"min": 20, "max": 80}
                                    });
                                    
                                    
    		
    </script>


    </body>

    </html>